const mysql = require("mysql2");
const options = {
  host: 'localhost',
  user: 'root',
  password: 'root',
  database: 'goods'
}
const pool = mysql.createPool(options)
const query = (sql, options, cb) => {
  console.log(options)
  pool.getConnection((err, conn) =>{
    if (err) throw err;
    else {
      conn.query(sql,options,function(err,results,fields){
        //事件驱动回调
          cb(err,results,fields);
      });
      conn.release();
    }
  });
}
function execSQL(sql) {
  return new Promise((resolve, reject) => {
    query(sql, (err, data) => {
      if (err) {
        reject(err);
        return
      }
      resolve(data);
    });
  })
}

module.exports = execSQL